
#pragma once



class CReverbDlg : public CDialogImpl<CReverbDlg>, public CWinDataExchange<CReverbDlg>
{
private:
	CTrackBarCtrl sliderDiffus;
	CTrackBarCtrl sliderRoomSize;
	TCHAR str[20];

	FXREVERB_PARAMETERS& Parameters;
	FXREVERB_PARAMETERS CurrentParameters;
public:
	enum { IDD = IDD_REVERB };

	CReverbDlg(FXREVERB_PARAMETERS& Param) : Parameters(Param) {} ;

	BEGIN_MSG_MAP(CReverbDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_ID_HANDLER(IDOK, OnOkCloseCmd)
		COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
		NOTIFY_HANDLER(IDC_SLIDER_DIFFUS, NM_CUSTOMDRAW, OnNMCustomdrawSliderDiffus)
		NOTIFY_HANDLER(IDC_SLIDER_ROOMSIZE, NM_CUSTOMDRAW, OnNMCustomDrawSliderRoomSize)
	END_MSG_MAP()

	BEGIN_DDX_MAP()
		DDX_TEXT(IDC_EDIT_DIFFUSION, str)
		DDX_TEXT(IDC_EDIT_ROOMSIZE, str)
		//DDX_INT(IDC_SLIDER_DIFFUS, Diffus)
		//DDX_INT(IDC_SLIDER_ROOMSIZE, RoomSize)

	END_DDX_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CenterWindow(GetParent());

		sliderDiffus.Attach(GetDlgItem(IDC_SLIDER_DIFFUS));
		sliderDiffus.SetRange((int)FXREVERB_MIN_DIFFUSION, (int)100 * FXREVERB_MAX_DIFFUSION,  true);
		//sliderDiffus.SetPos((int)100 * FXREVERB_DEFAULT_DIFFUSION);
		if (Parameters.Diffusion >= FXREVERB_MIN_DIFFUSION && Parameters.Diffusion <= FXREVERB_MAX_DIFFUSION){
			sliderDiffus.SetPos((int)100 * (Parameters.Diffusion));
			CurrentParameters.Diffusion = Parameters.Diffusion;
		} else {
			sliderDiffus.SetPos((int)100 * FXREVERB_DEFAULT_DIFFUSION);
			CurrentParameters.Diffusion = FXREVERB_DEFAULT_DIFFUSION;
		}
		
		sliderRoomSize.Attach(GetDlgItem(IDC_SLIDER_ROOMSIZE));
		sliderRoomSize.SetRange((int)100 * FXREVERB_MIN_ROOMSIZE, (int)100 * FXREVERB_MAX_ROOMSIZE,  true);
		//sliderRoomSize.SetPos((int) 100 * FXREVERB_DEFAULT_ROOMSIZE);
		if (Parameters.RoomSize >= FXREVERB_MIN_ROOMSIZE && Parameters.RoomSize <= FXREVERB_MAX_ROOMSIZE){
			sliderRoomSize.SetPos((int)100 * (Parameters.RoomSize));
			CurrentParameters.RoomSize = Parameters.RoomSize;
		} else {
			sliderRoomSize.SetPos((int)100 * FXREVERB_DEFAULT_ROOMSIZE);
			CurrentParameters.RoomSize = FXREVERB_DEFAULT_ROOMSIZE;
		}

		return TRUE;
	}

	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		EndDialog(wID);
		return 0;
	}

	LRESULT OnOkCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		Parameters = CurrentParameters;
		EndDialog(wID);
		return 0;
	}
	LRESULT OnNMCustomdrawSliderDiffus(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderDiffus.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_DIFFUSION);
		CurrentParameters.Diffusion = (float) nVal/100;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderRoomSize(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderRoomSize.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_ROOMSIZE);
		CurrentParameters.RoomSize = (float) nVal/100;
		if (CurrentParameters.RoomSize == 0)
			CurrentParameters.RoomSize = FXREVERB_MIN_ROOMSIZE;

		return 0;
	}

};
